<html>
<head><meta charset="utf-8"><title>Should this ICE-producing code compile? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html">Should this ICE-producing code compile?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="211213576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211213576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Casey Rodarmor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211213576">(Sep 25 2020 at 03:01)</a>:</h4>
<p>I'm running into an GAT-related ICE, and I'm not sure if:</p>
<ol>
<li>Once the ICE is fixed and GATs are landed, the code will compile and work.</li>
<li>The code is nonsensical, and eventually it will be rejected by the compiler with a proper error message.</li>
</ol>
<p>A minimal reproduction is here:</p>
<p><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=70754f24026748d70ef46f2e85af76bd">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=70754f24026748d70ef46f2e85af76bd</a></p>
<p>The error is <code>error: internal compiler error: impl item and trait item have different parameter counts</code>, which is the same as in <a href="https://github.com/rust-lang/rust/issues/68648">this issue</a>.</p>
<p>I put a comment before the bit that confuses me. Basically, I'm trying to bound an associated type like so: <code>type Bar: Bar&lt;Foo = Self&gt;;</code> but, inside of <code>Bar</code>, <code>Foo</code> is <code>    type Foo&lt;T&gt;;</code>, i.e. a GAT.</p>
<p>Does this bound make sense/is it something that might eventually compile? Trying to bound a GAT with a concrete type seems sketchy to me, but I'm not particularly sure of myself.</p>



<a name="211213947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211213947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Casey Rodarmor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211213947">(Sep 25 2020 at 03:09)</a>:</h4>
<p>Maybe it does make sense: When Foo&lt;T&gt; is instantiated, Foo::Bar will be a concrete type, and thus <code>Foo::Bar::Foo</code> will be a concrete type, and thus can be bounded by a concrete type. Is that the right logic?</p>



<a name="211216799"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211216799" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211216799">(Sep 25 2020 at 04:15)</a>:</h4>
<p>So, I don't think your repro is valid, in part because I don't think Rust has the syntax to deal with this (yet).</p>



<a name="211216808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211216808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211216808">(Sep 25 2020 at 04:15)</a>:</h4>
<p>Consider an alternative program:</p>



<a name="211216869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211216869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211216869">(Sep 25 2020 at 04:16)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=513f409ce0e6cb208d9cfac5679538a5">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=513f409ce0e6cb208d9cfac5679538a5</a></p>



<a name="211216873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211216873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211216873">(Sep 25 2020 at 04:16)</a>:</h4>
<p>This is pretty similar to your program, except there aren't any GATs</p>



<a name="211216887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211216887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211216887">(Sep 25 2020 at 04:17)</a>:</h4>
<p>That <code>type X: Bar&lt;Y = Self&gt;;</code> on <code>Foo</code> is basically your <code>type Bar: Bar&lt;Foo = Self&gt;;</code></p>



<a name="211216956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211216956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211216956">(Sep 25 2020 at 04:19)</a>:</h4>
<p>Basically, you're missing a generic</p>



<a name="211216970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211216970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211216970">(Sep 25 2020 at 04:19)</a>:</h4>
<p>Now, I haven't fully wrapped my head around this example and whether it <em>should</em> work (and what would need to be changed/added)</p>



<a name="211216975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211216975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211216975">(Sep 25 2020 at 04:19)</a>:</h4>
<p>But hopefully that helps a bit</p>



<a name="211217126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211217126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Casey Rodarmor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211217126">(Sep 25 2020 at 04:22)</a>:</h4>
<p>Unfortunately this is coming up in a project I'm working on where the generic cannot be removed, unlike in the example.</p>
<blockquote>
<p>Jack Huey: So, I don't think your repro is valid, in part because I don't think Rust has the syntax to deal with this (yet).</p>
</blockquote>
<p>Can you elaborate? Do you mean that what I wrote won't work without additional syntax?</p>



<a name="211217195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211217195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211217195">(Sep 25 2020 at 04:24)</a>:</h4>
<p>Give me a second. I'll think a bit more</p>



<a name="211217403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211217403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211217403">(Sep 25 2020 at 04:29)</a>:</h4>
<p>Hmm, so maybe this should work, since you aren't using the <code>T</code> on <code>Bar::Foo</code></p>



<a name="211217461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211217461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211217461">(Sep 25 2020 at 04:30)</a>:</h4>
<p>I would be interested to see if this compiles with <a href="https://github.com/rust-lang/rust/issues/73905">#73905</a></p>



<a name="211217568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211217568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211217568">(Sep 25 2020 at 04:33)</a>:</h4>
<p>If you wanted to use the <code>T</code> from <code>Bar::Foo</code> in the bound on <code>Foo::Bar</code>, then I think that's where syntax is a problem. (And indeed, the assumption that we can't name GAT generics in projection bounds is probably what is breaking here)</p>



<a name="211217923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211217923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Casey Rodarmor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211217923">(Sep 25 2020 at 04:42)</a>:</h4>
<p>Do you think this is the same as <a href="https://github.com/rust-lang/rust/issues/68648">#68648</a>?</p>
<p>I'll see if I can manage to get that commit building locally and try it out!</p>



<a name="211218003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211218003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211218003">(Sep 25 2020 at 04:44)</a>:</h4>
<p>Yep! That looks like the same problem. Specifically, this bit: <code>T: Fun&lt;F = T&gt;</code> from that issue</p>



<a name="211218034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211218034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211218034">(Sep 25 2020 at 04:45)</a>:</h4>
<p>Also found in <a href="https://github.com/rust-lang/rust/issues/71176">#71176</a></p>



<a name="211221903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211221903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Casey Rodarmor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211221903">(Sep 25 2020 at 06:15)</a>:</h4>
<p>Interestingly, <a href="https://github.com/rust-lang/rust/issues/68648">#68648</a> still fails with the same ICE when using rustc build from that PR, but the example I gave fails with a different ICE: <code>type parameter T/#1 (T/1) out of range when substituting, substs=[&lt;Self as Foo&lt;T&gt;&gt;::Bar]</code></p>



<a name="211223093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211223093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Casey Rodarmor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211223093">(Sep 25 2020 at 06:38)</a>:</h4>
<p>I made a repo with all the snippets and compilation errors and commented here: <a href="https://github.com/rust-lang/rust/pull/73905#issuecomment-698751243">https://github.com/rust-lang/rust/pull/73905#issuecomment-698751243</a></p>



<a name="211223101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Should%20this%20ICE-producing%20code%20compile%3F/near/211223101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Casey Rodarmor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Should.20this.20ICE-producing.20code.20compile.3F.html#211223101">(Sep 25 2020 at 06:38)</a>:</h4>
<p>The ICEs are still all there, but the error messages are more informative. Feels like a win ;)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>